/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
 var reverseList = function(head) {
     let newhead=null;
     let node=null;
    while(head!=null){
        newhead = head;
        head=head.next;
        newhead.next=node;
        node=newhead;
    }
    return newhead;
};